package demo.Thread;

/**
 * @Auther: hjy(lc))
 * @Date: 2022/8/10-08-10-19:52
 * @Description：demo.Thread
 */
/*
编写两个线程,一个线程打印1-52的整数，另一个线程打印字母A-Z。打印顺序为 12A34B56C….5152Z。
即按照整数和字母的顺序从小到大打印，并且每打印两个整数 后，打印一个字母，交替循环打印，直到打印到整数52和字母Z结束
 */
public class point_Thread {
    public static void main(String[] args) {
        Object obj = new Object();
        Thread thread1 = new Thread(){
            @Override
            public void run() {
                int count = 0;
                for (int i = 1; i < 53; i++) {
                    synchronized (obj){
                        count++;
                        System.out.print(i);
                        if(count == 2){
                            count=0;
                            try {
                                obj.notify();
                                obj.wait();
                            } catch (InterruptedException e) {
                                e.printStackTrace();
                            }
                        }
                        obj.notify();
                    }
                }
            }
        };
        Thread thread2 = new Thread(){
            @Override
            public void run() {
                int count = 0;
                for (int i = 0; i < 26; i++) {
                    synchronized (obj){
                        System.out.print((char)(i + 'A'));
                        try {
                            obj.notify();
                            obj.wait();
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                        obj.notify();
                    }
                }
            }
        };
        thread1.start();

        thread2.start();
    }
}
